<?php

App::uses('AppModel', 'Model');
App::uses('CompositeKeyModel', 'Model');

/**
 * Member Model
 *
 * @property Organisation $Organisation
 * @property MemberBiodata $MemberBiodata
 * @property MemberChild $MemberChild
 * @property OrganisationMemberContribution $OrganisationMemberContribution
 * @property OrganisationMemberAnniversary $OrganisationMemberAnniversary
 * @property OrganisationMemberGroup $OrganisationMemberGroup
 * @property MemberParent $MemberParent
 * @property MemberSpouse $MemberSpouse
 */
class Currency extends CompositeKeyModel {

    public $useDbConfig = "organisations";

    //The Associations below have been created with all possible keys, those that are not needed can be removed


    /**
     *
     *
     * @var array
     */
    public $hasMany = array(
        'ModuleMemberContribution' => array(
            'className' => 'ModuleMemberContribution',
            'foreignKey' => 'currency_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

    /**
     * belongsTo associations
     *
     * @var array
     */

    public $belongsTo = array(
        'Country' => array(
            'className' => 'Country',
            'foreignKey' => 'country_id',
            'conditions' => array('Currency.active'=>1),
            'fields' => '',
            'order' => ''
        )
    );


    public function getCurrencies() {
        return $this->find('all', array(
            'conditions' => array(
                'Currency.active' => 1
            ),
            'recursive'=>-1
        ));
    }

    public function getCurrency($currency_id) {
        return $this->find('first', array(
            'conditions' => array(
                'Currency.id' => $currency_id,
                'Currency.active' => 1
            ),
            'contain'=>array(
                'Country'=>array('fields'=>array('Country.id','Country.name','Country.capital'))
            ),
            'recursive'=>1
        ));
    }



    /**
     * Flags the specified member as deleted in the organisation
     *
     * @param type $organisation_id
     * @param type $member_id
     * @return type
     */
    public function deleteCurrency($currency_id) {
        return $this->save(array(
            'id' => $currency_id,
            'active' => 0
        ));
    }
}
